package com.lottemall.gateway.config;

import com.lottemall.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * 主要用来网关拦截未登录
 */
@Slf4j
@Data
@ConfigurationProperties(prefix = "lt.jwt")
public class JwtProperties {


    private String pubKeyPath;
    private String cookieName;
    private PublicKey publicKey;
    /**
     * @PostContruct：在构造方法执行之后执行该方法
     */
    @PostConstruct
    public void init() {
        try {
            //读取公钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            log.error("初始化公钥失败",e);
            throw new RuntimeException();
        }
    }
}
